﻿using System;
using System.Linq;
using WebFormsMvp.Contrib.Data.Services;
using WebFormsMvp.Contrib.Views;

namespace WebFormsMvp.Contrib.Presenters
{
    /// <summary>
    /// 
    /// </summary>
    public class NewsArchivePresenter : Presenter<INewsArchiveView>
    {
        protected INewsService dataService;

        public NewsArchivePresenter(INewsArchiveView view, INewsService dataService) : base(view)
        {
            this.dataService = dataService;
            view.Load += new EventHandler(View_Load);
        }

        protected virtual void View_Load(object sender, EventArgs e)
        {
            this.View.Model.NewsArticles = this.dataService.GetNewsArticles().Take(this.View.NumberOfArticles);
        }

        public override void ReleaseView()
        {
            this.View.Load -= new EventHandler(View_Load);
        }
    }
}
